package com.alks.function.data.dto.chengKong.assort;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;

@Getter
@Setter
@NoArgsConstructor
public class YfBomPartNewDto {

    @ApiModelProperty(value = "序号",name = "seqNo")
    private String seqNo;

    @ApiModelProperty(value = "部位",name = "partName")
    private String partName;

    @ApiModelProperty(value = "段",name = "segment")
    private String segment;

    @ApiModelProperty(value = "物料编码",name = "mtlNo")
    private String mtlNo;

    @ApiModelProperty(value = "材料名称",name = "mtlName")
    private String mtlName;

    @ApiModelProperty(value = "材料颜色",name = "mtlColor")
    private String mtlColor;

    @ApiModelProperty(value = "规格",name = "mtlSpec")
    private String mtlSpec;

    @ApiModelProperty(value = "单位",name = "mtlUnit")
    private String mtlUnit;

    @ApiModelProperty(value = "尺码起",name = "size1")
    private String size1;

    @ApiModelProperty(value = "尺码止",name = "size2")
    private String size2;

    @ApiModelProperty(value = "供应商",name = "vendor")
    private String vendor;

    @ApiModelProperty(value = "用量",name = "usage")
    private BigDecimal usage;

    @ApiModelProperty(value = "计算方式",name = "usageType")
    private String usageType;

    @ApiModelProperty(value = "领用单位",name = "drawDept")
    private String drawDept;

    @ApiModelProperty(value = "号码类型",name = "sizeType")
    private String sizeType;

    @ApiModelProperty(value = "主辅料",name = "mtlProperty")
    private String mtlProperty;

    @ApiModelProperty(value = "捡料",name = "noLotUsage")
    private String noLotUsage;

    @ApiModelProperty(value = "备注",name = "remark")
    private String remark;

    @ApiModelProperty(value = "被复制型体",name = "styleCopyTemp")
    private String styleCopyTemp;

    @ApiModelProperty(value = "被复制颜色",name = "colorCopyTemp")
    private String colorCopyTemp;
    private String orderIdCopyTemp;
    private String orderId;

    @ApiModelProperty("供货方式")
    private String vendorType;

    @ApiModelProperty("联系方式")
    private String phone;

    @ApiModelProperty("部件加工方式")
    private String process;

    @ApiModelProperty("用量是否超标（≥0.05码）")
    private String colorFlag;

    @ApiModelProperty("米转码的用量")
    private BigDecimal newUsage;

    // ================= 新增方法 =================

    /**
     * 根据单位和用量自动判断是否超标（相当于 ≥ 0.05 码）
     */
    public void calculateColorFlag() {
        this.colorFlag = "N"; // 默认不超标

        if (this.usage == null || this.mtlUnit == null) {
            return;
        }

        // 统一转为大写，便于比较
        String unit = this.mtlUnit.trim().toUpperCase();
        BigDecimal usage = this.usage;

        // 情况1：单位是“码”或“Y”
        if ("码".equals(this.mtlUnit.trim()) || "Y".equals(unit)) {
            if (usage.compareTo(new BigDecimal("0.05")) >= 0) {
                this.colorFlag = "Y";
            }
        }
        // 情况2：单位是“米”
        else if ("米".equals(this.mtlUnit.trim())) {
            BigDecimal usageInYard = usage.multiply(new BigDecimal("1.0936"));
            if (usageInYard.compareTo(new BigDecimal("0.05")) >= 0) {
                this.colorFlag = "Y";
                this.newUsage = usageInYard;
            }
        }
        // 其他单位不做处理，默认 "N"
    }
}
